﻿/********************************************************************************
     File:																
            Manager.aspx.cs                         
     Description:
            动态(公告)信息管理
     Author:									
            DDBuildTools
            http://DDBuildTools.supesoft.com
     Finish DateTime:
            2011-7-28 16:36:37
     History:
*********************************************************************************/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using BingZi.HY.Core.Entities.Center;
using BingZi.HY.Core.Enums;
using BingZi.HY.Core;
using BingZi.HY.Core.Message;
using BingZi.HY.Core.WebControls;




namespace BingZi.HY.UI.Center.Manager.app_TrendsUI
{
    public partial class Manager : BingZi.HY.Core.BLL.PageBase
    {
        Int32 IDX = (Int32)BingZi.HY.Core.Common.sink("IDX", BingZi.HY.Core.Enums.MethodType.Get, 10, 0, DataType.Int);
        string CMD = (string)BingZi.HY.Core.Common.sink("CMD", BingZi.HY.Core.Enums.MethodType.Get, 10, 1, DataType.Str);
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckPagePermission(CMD);
            if (!Page.IsPostBack)
            {
                OnStart();
            }
        }
        
        /// <summary>
        /// 开始操作
        /// </summary>
        private void OnStart()
        {
            app_Trends ut = app_Trends.FindByKeyForEdit(IDX);
            OnStartData(ut);
            switch (CMD)
            { 
                case "New":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "增加动态(公告)信息";
                    Hidden_Disp();
                    break;
                case "List":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "查看动态(公告)信息";
                    Hidden_Input();
                    ButtonOption.Visible = false;
                    AddEditButton();
                    break;
                case "Edit":
                    TabOptionItem1.Tab_Name = HeadMenuWebControls1.HeadOPTxt = "修改动态(公告)信息";
                    Hidden_Disp();
                    AddDeleteButton();
                    break;
                case "Delete":
                    
                    if(ut.Delete() > 0)
                    {
                        EventMessage.MessageBox(1, "删除成功", string.Format("删除ID:{0}成功!", IDX), Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    else {
                        EventMessage.MessageBox(1, "删除失败", string.Format("删除ID:{0}失败!", IDX), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    }
                    break;
                default :
                    EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
                    break;
            }
        }

        /// <summary>
        /// 增加修改按钮
        /// </summary>
        private void AddEditButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Edit;
            bi.ButtonName = "动态(公告)信息";
            bi.ButtonUrl = string.Format("?CMD=Edit&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);
        }


        /// <summary>
        /// 增加删除按钮
        /// </summary>
        private void AddDeleteButton()
        {
            HeadMenuButtonItem bi = new HeadMenuButtonItem();
            bi.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.Delete;
            bi.ButtonName = "动态(公告)信息";
            bi.ButtonUrlType = UrlType.JavaScript;
            bi.ButtonUrl = string.Format("DelData('?CMD=Delete&IDX={0}')", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi);

            HeadMenuButtonItem bi1 = new HeadMenuButtonItem();
            bi1.ButtonPopedom = NewLife.CommonEntity.PermissionFlags.List;
            bi1.ButtonIcon = "back.gif";
            bi1.ButtonName = "返回";
            bi1.ButtonUrl = string.Format("?CMD=List&IDX={0}", IDX);
            HeadMenuWebControls1.ButtonList.Add(bi1);
        }

        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="ut"></param>
        private void OnStartData(app_Trends ut)
        {
        T_Title_Input.Text = T_Title_Disp.Text = ut.T_Title.ToString();
                T_Description_Input.Text = T_Description_Disp.Text = ut.T_Description.ToString();
                T_Photo_Input.Text = T_Photo_Disp.Text = ut.T_Photo.ToString();
                T_StartTime_Input.Text = T_StartTime_Disp.Text = ut.T_StartTime.ToString();
                T_LastTime_Input.Text = T_LastTime_Disp.Text = ut.T_LastTime.ToString();
                T_LastUserID_Input.Text = T_LastUserID_Disp.Text = ut.T_LastUserID.ToString();
                T_Top_Input.Text = T_Top_Disp.Text = ut.T_Top.ToString();
                T_Red_Input.Text = T_Red_Disp.Text = ut.T_Red.ToString();
                
        }

        /// <summary>
        /// 隐藏输入框
        /// </summary>
        private void Hidden_Input()
        {
        T_Title_Input.Visible = false;
        T_Description_Input.Visible = false;
        T_Photo_Input.Visible = false;
        T_StartTime_Input.Visible = false;
        T_LastTime_Input.Visible = false;
        T_LastUserID_Input.Visible = false;
        T_Top_Input.Visible = false;
        T_Red_Input.Visible = false;
        
        }

        /// <summary>
        /// 隐藏显示框
        /// </summary>
        private void Hidden_Disp()
        {
        T_Title_Disp.Visible = false;
        T_Description_Disp.Visible = false;
        T_Photo_Disp.Visible = false;
        T_StartTime_Disp.Visible = false;
        T_LastTime_Disp.Visible = false;
        T_LastUserID_Disp.Visible = false;
        T_Top_Disp.Visible = false;
        T_Red_Disp.Visible = false;
        
        }

        /// <summary>
        /// 增加/修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
        
            string T_Title_Value = (string)BingZi.HY.Core.Common.sink(T_Title_Input.UniqueID, MethodType.Post, 128, 1, DataType.Str);
            string T_Description_Value = (string)BingZi.HY.Core.Common.sink(T_Description_Input.UniqueID, MethodType.Post, 2147483647, 1, DataType.Str);
            string T_Photo_Value = (string)BingZi.HY.Core.Common.sink(T_Photo_Input.UniqueID, MethodType.Post, 128, 0, DataType.Str);
            DateTime T_StartTime_Value = (DateTime)BingZi.HY.Core.Common.sink(T_StartTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            DateTime T_LastTime_Value = (DateTime)BingZi.HY.Core.Common.sink(T_LastTime_Input.UniqueID, MethodType.Post, 20, 1, DataType.Dat);
            int T_LastUserID_Value = (int)BingZi.HY.Core.Common.sink(T_LastUserID_Input.UniqueID, MethodType.Post, 10, 1, DataType.Int);
            int T_Top_Value = (int)BingZi.HY.Core.Common.sink(T_Top_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            int T_Red_Value = (int)BingZi.HY.Core.Common.sink(T_Red_Input.UniqueID, MethodType.Post, 3, 1, DataType.Int);
            app_Trends ut = app_Trends.FindByKeyForEdit(IDX);
            
            ut.T_Title = T_Title_Value;
            ut.T_Description = T_Description_Value;
            ut.T_Photo = T_Photo_Value;
            ut.T_StartTime = T_StartTime_Value;
            ut.T_LastTime = T_LastTime_Value;
            ut.T_LastUserID = T_LastUserID_Value;
            ut.T_Top = T_Top_Value;
            ut.T_Red = T_Red_Value;
            
            Int32 rInt =0; if (CMD == "New")
            {
                rInt = ut.Insert();
            }
            else if (CMD == "Edit")
            {
                rInt = ut.Update();
            }
            else
            {
                EventMessage.MessageBox(2, "不存在操作字符串!", "不存在操作字符串!", Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
            
            if ( rInt> 0)
            {
                string OpTxt = string.Format("增加动态(公告)信息成功!(ID:{0})", rInt);
                if(CMD == "Edit")
                    OpTxt = string.Format("修改动态(公告)信息成功!(ID:{0})",IDX);
                EventMessage.MessageBox(1, "操作成功", OpTxt, Icon_Type.OK, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else if (rInt == -2)
            {
                EventMessage.MessageBox(1, "操作失败", "操作失败,存在相同的键值(用户名/数据)!", Icon_Type.Alert, Common.GetHomeBaseUrl("Default.aspx"));
            }
            else
            {
                EventMessage.MessageBox(1, "操作失败", string.Format("操作失败,返回值:{0}!", rInt), Icon_Type.Error, Common.GetHomeBaseUrl("Default.aspx"));
            }
        }
    }
}
